package com.example.gamestore.control;

import com.example.gamestore.Bean.Content;
import com.example.gamestore.Bean.User;
import com.example.gamestore.aop.AdminLogAnnotation;
import com.example.gamestore.mapper.ContentMapper;
import com.example.gamestore.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
public class  ContentControl {
    @Autowired
    private ContentMapper contentMapper;
    @PostMapping("/addcontent")
    @AdminLogAnnotation(module = "商城模块",operater = "添加评论")
    public String addcontent(Content content, HttpSession session){
        Integer gameId = content.getGameId();
        User user =(User) session.getAttribute("user");
        content.setCreatetime(new Date());
        content.setAuthorId(user.getId());
        contentMapper.insert(content);
        return "redirect:/gamesdetails?id="+gameId;
    }
}
